home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / ae / code / ax3.00 / aemci.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-03  |  17.0 KB  |  538 lines

  1. #include "bbs.h"
  2.  
  3. extern int Online_Baud;
  4. int width;
  5. extern int gnsflag;
  6. extern long Time_Last_On;
  7. extern char *ComputerTypes[];
  8. extern int System_Calls;
  9. extern char Conference_Location[];
  10. extern int LineCount;
  11. extern int NotRelative;
  12. extern int CN;
  13. //extern BOOL MCIDoor;
  14. extern int MCIViewSafe;
  15. int mciinterpret(int dtlen,char image[],BOOL returnit);
  16. int mciread(BPTR fi,char *b,int *pos,int *myeof);
  17. int mciread(BPTR fi,char *b,int *pos,int *myeof)
  18. {
  19.   register int returnval;
  20.   if(*(b+(*pos))==NULL)
  21.   {
  22.     if(*myeof) return(0);
  23.     if((returnval=FRead(fi,(APTR)b,1L,400L))<400L) *myeof=1;
  24.     *(b+returnval)='\0';
  25.     *pos=0; returnval=(int)b[*pos]; (*pos) +=1; return(returnval);
  26.   }
  27.   returnval=(int)b[*pos]; (*pos)+=1;
  28.   return(returnval);
  29. }
  30. int mcisend(char *filename)
  31. {
  32.    BPTR fi;
  33.    char image[200];
  34.    char myimage[402];
  35.    BOOL returnit=FALSE;
  36.    int stats;
  37.    UBYTE dot='|';
  38.    int dtlen;
  39.    int myeof=0;
  40.    int pos=0;
  41.    BOOL noteof;
  42.    char ch[10];
  43.    ch[1]='\0';
  44.    myimage[0]='\0';
  45.    if(!MCIViewSafe && !GET_BIT(ACS_MCI_MSG)) return(SUCCESS);
  46.    fi=Open(filename,MODE_OLDFILE); if(fi==NULL) return(SUCCESS);
  47.    while((ch[0]=mciread(fi,myimage,&pos,&myeof))!=NULL)
  48.    {
  49.       if(ch[0]==13 || ch[0]==12 || ch[0]==10) 
  50.       { 
  51.          AEPutStr("\r\n");
  52.          if(stats=CheckForPause())
  53.          {
  54.            AEPutStr("\r\n");
  55.            Close(fi);
  56.            ConPutStr(" p");
  57.            return(stats);
  58.          } 
  59.          
  60.       
  61.       if(SCheckInput())
  62.       {
  63.          stats=ReadChar(1L);
  64.          if(stats<0) 
  65.          { Close(fi);
  66.            ConPutStr(" p");
  67.            return(stats);
  68.          }
  69.       } continue;
  70.       }   
  71.       if(ch[0]=='~')
  72.       {
  73.         dtlen=0;
  74.         image[0]='\0';
  75.         while((noteof=mciread(fi,myimage,&pos,&myeof))!=NULL)
  76.         {
  77.           ch[0]=noteof;
  78.           image[dtlen]=noteof;
  79.           if(image[0]<' ') { image[1]='\0';break; }
  80.           if(dot==(UBYTE)noteof || noteof==' ') break;
  81.           if(noteof==10 || noteof==12 || noteof==13)
  82.           { ch[0]='\0'; returnit=TRUE; break;}
  83.           dtlen++;
  84.           
  85.           if(dtlen>100) { Close(fi); return(SUCCESS);}
  86.         }
  87.         if(!noteof) { Close(fi); return(SUCCESS); }
  88.         image[dtlen]='\0';
  89.         if(stats=mciinterpret(dtlen,image,returnit)!=SUCCESS)
  90.         {Close(fi); return(stats); break;}
  91.       }
  92.       else AEPutStr(ch);
  93.     } 
  94.     Close(fi);
  95. ConPutStr(" p");
  96.           
  97.   return(SUCCESS);
  98. }
  99. int mciputstr(char *str)
  100. {
  101.    register int i;
  102.    char image[200];
  103.    BOOL returnit=FALSE;
  104.    UBYTE dot='|';
  105.    int dtlen;
  106.    int stats;
  107.    BOOL noteof;
  108.    char ch[10];
  109.    i=0; 
  110.    if(!MCIViewSafe && !GET_BIT(ACS_MCI_MSG)) return(SUCCESS);
  111.    while(*(str+i)!=NULL)
  112.    {
  113.       ch[0]=*(str+i); i++;
  114.       if(ch[0]==13 || ch[0]==12 || ch[0]==10) 
  115.       { 
  116.          AEPutStr("\r\n");
  117.          if(stats=CheckForPause())
  118.          {
  119.            AEPutStr("\r\n");
  120.            return(stats);
  121.          } 
  122.          
  123.       
  124.       if(SCheckInput())
  125.       {
  126.          stats=ReadChar(1L);
  127.          if(stats<0) 
  128.          { 
  129.            return(stats);
  130.          }
  131.       } continue;
  132.       }
  133.       if(ch[0]=='~')
  134.       {
  135.         dtlen=0;
  136.         image[0]='\0';
  137.         noteof=TRUE;
  138.         while(1)
  139.         {
  140.           if(*(str+i)==NULL) { noteof=FALSE; break; }
  141.           ch[0]=*(str+i);
  142.           image[dtlen]=ch[0];
  143.           if(image[0]<' ') {  i++; image[1]='\0';break; }
  144.           if(dot==(UBYTE)ch[0] || ch[0]==' ') { i++;break; }
  145.           if(ch[0]==10 || ch[0]==12 || ch[0]==13)
  146.           { ch[0]='\0'; i++;  returnit=TRUE; break;}
  147.           dtlen++; i++;
  148.           
  149.           if(dtlen>100) { return(SUCCESS);}
  150.           if(ch[0]=='r' && dtlen==1) break;
  151.         }
  152.         if(image[0]=='r') { image[dtlen]='1'; image[0]='n'; dtlen++; }
  153.         if(!noteof) { return(SUCCESS); }
  154.         image[dtlen]='\0';
  155.         if(mciinterpret(dtlen,image,returnit)!=SUCCESS) break;
  156.        }
  157.       else {ch[1]='\0'; AEPutStr(ch);}
  158.     }
  159.   return(SUCCESS);
  160. }
  161.  
  162. int mciinterpret(int dtlen,char *image,BOOL returnit)
  163. {
  164.    char prt[200];
  165.    char tprt[200];
  166.    char confname[100]; char confloc[100];
  167.    int i;
  168.    int stats;
  169.    int width,pt,temp;
  170.     prt[0]='\0';
  171.         if(image[0]=='~')
  172.         {
  173.           strcpy(prt,image);
  174.         }else
  175.         {
  176.           width=-1;pt=0;
  177.           while(pt<dtlen)
  178.           {
  179.             switch(image[pt])
  180.             {
  181.               case 'M': sprintf(tprt,"%d",User.Messages_Posted);
  182.                         strlim(prt,tprt,width); width=-1; break;
  183.               case 'A': sprintf(tprt,"%d",User.Sec_Status);
  184.                         strlim(prt,tprt,width); width=-1; break;
  185.  
  186.               case 'S': 
  187.                 switch(image[pt+1])
  188.                 {
  189.                    case 'C':
  190.                         sprintf(tprt,"%d",System_Calls);
  191.                         strlim(prt,tprt,width); width=-1; break;
  192.  
  193.                    case 'S':
  194.                         if(!Restricted(&image[pt+3]))
  195.                         { 
  196.                           if(!MCIViewSafe && AllowedView(&image[pt+3])){
  197.                           gnsflag=0;MenuSend24(&image[pt+3],LineCount);}
  198.                           else
  199.                           if(MCIViewSafe)
  200.                           {gnsflag=0;MenuSend24(&image[pt+3],LineCount);}
  201.                         }
  202.             break;
  203.  
  204.                    case 'P':
  205.                         stats=DoPause();
  206.                         if(stats<0) return(stats);
  207.                         strcpy(prt,""); break;
  208.  
  209.                    case 'R':
  210.  
  211.             strcpy(GSTR1,&image[pt+3]);
  212.             i=0;
  213.             while(GSTR1[i])
  214.             {
  215.             if(GSTR1[i]=='/')
  216.                 {
  217.                 GSTR1[i]='\0';
  218.                 strcpy(GSTR2,&GSTR1[i+1]);
  219.                 break;
  220.                 }
  221.             i++;
  222.             }
  223.  
  224.                         gnsflag=0;
  225.  
  226.             sprintf(prt,"%s/%-3.3d.%s",GSTR1,rnd(width)+1,GSTR2);
  227.                         if(ChecktoDisplay(prt,tprt,0,1)<0) return(NO_CARRIER);
  228.  
  229.             strcpy(prt,"");
  230.             width=-1;
  231.             break;
  232.  
  233.                    default:
  234.  
  235.                         sprintf(tprt,"%d",User.Slot_Number);
  236.                         strlim(prt,tprt,width); width=-1; break;
  237.              
  238.                 } break;
  239.               case 'N': strlim(prt,User.Name,width); width=-1; break;
  240.               case '#': strlim(prt,User.PhoneNumber,width); width=-1; break;
  241.               case 'c': sprintf(prt,"%cm",image[pt+1]); break;
  242.               case 'z': sprintf(prt,"%cm",image[pt+1]); break;
  243.               case 'n': temp=image[pt+1]-'0'; if(temp<=0 || temp>9) temp=1;
  244.                         while(temp)
  245.                         { 
  246.                           AEPutStr("\r\n");
  247.                           if(stats=CheckForPause())
  248.                           {
  249.                             AEPutStr("\r\n");
  250.                             return(stats);
  251.                           } temp--; 
  252.                         }
  253.                         strcpy(prt,"");
  254.                         break;
  255.               case 'T':
  256.                    switch(image[pt+1])
  257.                    {
  258.                      case 'C': sprintf(tprt,"%u",User.Times_Called);
  259.                                strlim(prt,tprt,width); width=-1; break;
  260.                      case 'L': sprintf(tprt,"%ld",User.Time_Limit/60L);
  261.                                strlim(prt,tprt,width); width=-1; break;
  262.                      case 'R': sprintf(tprt,"%ld",Time_limit/60L);
  263.                                strlim(prt,tprt,width); width=-1; break;
  264.                     } break;
  265.               case 'C':
  266.                    switch(image[pt+1])
  267.                    {
  268.                      case 'A': strlim(prt,User.Conference_Access,width); width=-1; break;
  269.                      case 'R': strcpy(prt,""); 
  270.                                if(image[pt+2]!='\0' && image[pt+3]!='\0')
  271.                                strcpy(prt,&image[pt+3]);prt[0]=HtKey(prt);
  272.                               AEPutStr("\r\n");
  273.                                LineCount=0;
  274.                              strcpy(prt,""); break;
  275.                      case 'E': strcpy(prt,"CE"); break;
  276.                      case 'D': strcpy(prt,"CD"); break;
  277.                      case 'T': 
  278.                                strcpy(tprt,GetTheTime(NULL));
  279.                                strlim(prt,tprt,width); width=-1; break;
  280.                      case 'C': 
  281.                                
  282.                                strcpy(prt,&image[pt+3]);
  283.                                if(MCIViewSafe)
  284.                                {
  285.                                   sprintf(tprt,"%sCommands/SysCmd/",Cmds->BBSLoc);
  286.                                   if(!CustomCommand(tprt,prt,1))
  287.                                   {
  288.                                     sprintf(tprt,"%sCommands/BBSCmd/",Cmds->BBSLoc);
  289.                                     if(!CustomCommand(tprt,prt,1))
  290.                                     {
  291.                                       sprintf(tprt,"%sCommands/conf%dCmd/",Cmds->BBSLoc,CN);
  292.                                       CustomCommand(tprt,prt,1);
  293.                                     }
  294.                                   }
  295.                                }
  296.                                else
  297.                                {
  298.                                     sprintf(tprt,"%sCommands/BBSCmd/",Cmds->BBSLoc);
  299.                                     if(!CustomCommand(tprt,prt,0))
  300.                                     {
  301.                                       sprintf(tprt,"%sCommands/conf%dcmd/",Cmds->BBSLoc,CN);
  302.                                       CustomCommand(tprt,prt,0);
  303.                                     }
  304.                                }
  305.                                strcpy(prt,"");
  306.                                break;
  307.                      case 'L': stats = 0; width=0;if(image[pt+2]!='\0') tprt[0]=image[pt+2];
  308.                                else tprt[0]=' '; tprt[1]='\0';
  309.                                  while(stats<Boards_Are_Active)
  310.                                  {
  311.                                       
  312.                                    if(IsValidConf(stats))
  313.                                    {
  314.                                      GetConfName(confname,confloc,stats);
  315.                                      width++;
  316.                                      sprintf(prt,"                     %3d",width);
  317.                                      AEPutStr(prt);
  318.                                      temp=strlen(confname);
  319.                                      while(temp<30) { AEPutStr(tprt); temp++; }
  320.                                      sprintf(prt,"%s\r\n",confname);
  321.                                      AEPutStr(prt);
  322.                                    }
  323.                                    stats++;
  324.                                  }
  325.                                  GetConfName(confname,confloc,CN-1);
  326.                                strcpy(prt,""); width = -1;break;
  327.                    }
  328.                    break;
  329.               case 'D': 
  330.                    switch(image[pt+1])
  331.                    {
  332.                      case 'T': strcpy(tprt,GetTheDate(NULL));strlim(prt,tprt,width); width=-1; break;
  333.                      case 'B': sprintf(tprt,"%ld",User.Bytes_Download);
  334.                                strlim(prt,tprt,width); width=-1; break;
  335.                      default: strcpy(prt,""); break;
  336.                    }break;
  337.                case 'F':
  338.                  switch(image[pt+1])
  339.                  {
  340.                    case 'U': sprintf(tprt,"%d",User.Uploads);
  341.                              strlim(prt,tprt,width); width=-1; break;
  342.                    case 'D': sprintf(tprt,"%d",User.Downloads);
  343.                              strlim(prt,tprt,width); width=-1; break;
  344.                    default: strcpy(prt,"F"); break;
  345.                  }break;
  346.                case 'H':
  347.                  switch(image[pt+1])
  348.                  {
  349.                    case 'W': strlim(prt,ComputerTypes[User.Sec_Bulletin],width); width=-1; break;
  350.                  }break;
  351.                case 'L':
  352.                  switch(image[pt+1])
  353.                  {
  354.                    case 'C':
  355.                       sprintf(tprt,"%s",ctime(&Time_Last_On));
  356.                       tprt[strlen(tprt)-1]='\0';
  357.                       strlim(prt,tprt,width); width=-1;
  358.                       break;
  359.                    case 'G':
  360.                       sprintf(tprt,"%d",Cmds->AcLvl[LVL_NODE_NUMBER]);
  361.                       strlim(prt,tprt,width); width=-1; break;
  362.                    
  363.                  }break;
  364.                case 'U':
  365.                  switch(image[pt+1])
  366.                  {
  367.                    case 'L': strlim(prt,User.Location,width); width=-1; break;
  368.                    case 'B': sprintf(tprt,"%ld",User.Bytes_Upload);
  369.                              strlim(prt,tprt,width); width=-1; break;
  370.                  } break;
  371.                case 'B':
  372.                  switch(image[pt+1])
  373.                  {
  374.                    case 'D': sprintf(tprt,"%ld",User.Daily_Bytes_Limit);
  375.                              strlim(prt,tprt,width); width=-1; break;
  376.                    case 'R': sprintf(tprt,"%d",Online_Baud);
  377.                              strlim(prt,tprt,width); width=-1; break;
  378.                    default: strcpy(prt,"B"); break;
  379.                  }break;
  380.                case 'W': if(width<0) width=1;
  381.                    Delay((LONG)width); width=-1; break;
  382.                case 'b':
  383.                  sprintf(prt,"%cm",image[pt+1]); break;
  384.                case 'h':
  385.                  while(image[pt+1]!='0')
  386.                  {
  387.                     AEPutStr("\b \b"); image[pt+1] -=1;
  388.                  } break;
  389.                case 'q':
  390.                  strcpy(prt,""); break;
  391.                case 'x': temp=atoi(&image[pt+1]);
  392.                          sprintf(tprt,"%dH",temp);
  393.                          strcpy(prt,tprt); break;
  394.                case 'y': temp=atoi(&image[pt+1]);
  395.                          sprintf(tprt,"%d;",temp);
  396.                          strcpy(prt,tprt); break;
  397.   
  398.                case 'f':
  399.                  temp=image[pt+1]-'0';
  400.                  if(temp==0) strcpy(prt,"\x9B\x48");
  401.                else strcpy(prt,"\x0c"); break;
  402.                case '0':
  403.                case '1':
  404.                case '2':
  405.                case '3':
  406.                case '4':
  407.                case '5':
  408.                case '6':
  409.                case '7':
  410.                case '8':
  411.                case '9':
  412.                  if(pt==0)
  413.                  {
  414.                     width=atoi(image); if(width>80) width=80;
  415.                     while(image[pt]>='0' && image[pt]<='9') pt++;break;
  416.                  }
  417.                  
  418.                  break; 
  419.               default: strcpy(prt,image);
  420.                }
  421.             if(width==-1)break;
  422.            }
  423.          }        
  424.         AEPutStr(prt);
  425.         if(returnit==TRUE)
  426.         { AEPutStr("\r\n");
  427.          if(stats=CheckForPause())
  428.          {
  429.            AEPutStr("\r\n");
  430.            return(stats);
  431.          }
  432.          returnit=FALSE;
  433.        } 
  434.   return(SUCCESS);
  435. }
  436. int Restricted(char *str)
  437. {
  438.    BPTR  FLock;
  439.    char image[200];
  440.    int bad=TRUE;
  441.    struct FileInfoBlock *FBlock;
  442.    if((FLock=Lock(str,ACCESS_READ))!=0)
  443.    {
  444.      if((FBlock=(struct FileInfoBlock *)AllocDosObject(DOS_FIB,NULL)) == NULL)
  445.      { 
  446.        AEPutStr("\r\nCan't allocate memory to lock file!!\r\n"); bad=TRUE; 
  447.      }
  448.      else 
  449.      { 
  450.        if((Examine(FLock,FBlock))==0)
  451.        {  
  452.          AEPutStr("\r\nCan't get informations from file.\r\n"); 
  453.          bad=TRUE;  
  454.        }
  455.        else
  456.        { 
  457.      
  458.          if(!strnicmp(FBlock->fib_Comment,"Restricted",10))
  459.          { 
  460.            AEPutStr("\r\n "); AEPutStr(str); 
  461.            AEPutStr("\r\n >>Restricted File<< Updating CallersLog\r\n");
  462.            sprintf(image,"\tAttempt to examine RESTRICTED file [%.100s]\n",str);
  463.            CallersLog(image);
  464.            bad=TRUE;
  465.          }
  466.          else  
  467.          {  
  468.            bad=FALSE;//!AllowedView(FBlock->fib_Comment);  
  469.          }
  470.        }
  471.        FreeDosObject(DOS_FIB,FBlock);
  472.     }
  473.     UnLock(FLock);
  474.    }
  475.     return(bad);
  476. }
  477. int AllowedView(char *str)
  478. {
  479.    BPTR  FLock;
  480.    char image[200];
  481.    struct FileInfoBlock *FBlock;
  482.    if((FLock=Lock(str,ACCESS_READ))!=0)
  483.    {
  484.      if((FBlock=(struct FileInfoBlock *)AllocDosObject(DOS_FIB,NULL))==NULL)
  485.      { 
  486.        AEPutStr("\r\nCan't allocate memory to lock file!!\r\n"); 
  487.      }
  488.      else 
  489.      { 
  490.        if((Examine(FLock,FBlock))==0)
  491.        {  
  492.          AEPutStr("\r\nCan't get informations from file.\r\n"); 
  493.            
  494.        }
  495.        else
  496.        { 
  497.          if(!strnicmp(FBlock->fib_Comment,"Allowed",7))
  498.          {
  499.            FreeDosObject(DOS_FIB,FBlock);
  500.            UnLock(FLock);return(TRUE);
  501.          }
  502.            if(!strwild(FBlock->fib_Comment,"{~~~}Allowed",'~',12))
  503.            { 
  504.              strcpy(image,FBlock->fib_Comment);
  505.              if(atoi(&image[1])<=User.Sec_Status)
  506.              {
  507.                FreeDosObject(DOS_FIB,FBlock);
  508.                 UnLock(FLock);return(TRUE);
  509.              }
  510.            }
  511.          
  512.        }
  513.        FreeDosObject(DOS_FIB,FBlock);
  514.  
  515.     }
  516.     UnLock(FLock);
  517.    }
  518.     return(FALSE);
  519. }
  520. /*
  521. int strwild(char *str,char *str1,char wild,int len)
  522. {
  523.    register int i=0;
  524.    char im1[200];char im2[200];
  525.    strcpy(im1,str);
  526.    strcpy(im2,str1);
  527.    strupr(im1);strupr(im2);
  528.    if(im1[0]=='\0') return(1);
  529.    while(im1[i] && i<len)
  530.    {
  531.      if(im2[i]=='\0') return(1);
  532.      if(im2[i]==wild ) { i++; continue; }
  533.      if(im1[i]!=im2[i]) return(1);
  534.      i++;
  535.    }
  536.    return(0);
  537. }
  538. */